<?php

namespace Modules\Auth\Entities;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Laravel\Passport\HasApiTokens;
use Modules\Common\Entities\Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class Admin extends Authenticatable
{
    use HasFactory;


    use HasApiTokens;
    use HasRoles;
    use HasFactory;

    protected $fillable = [];
    protected $appends = [
        'role_name'
    ];

    public function getRoleNameAttribute($key)
    {

        return $this->getRoleNames();
    }
    protected static function newFactory()
    {
        return \Modules\Auth\Database\factories\AdminFactory::new();
    }
    public function findForPassport($username) {
        return $this->where('name', $username)->first();
    }
    public function guardName(): string {
        return 'admin';
    }
    /**
     * @return bool
     */
    public function getSuperAdminAttribute(){
        return !!$this->is_super;
    }
    public function scopeAdmin($query){
        return $query->where("guard_name",'admin');
    }

}
